#ifndef classFLOBOSSH
 #define classFLOBOSSH


 #include "TypeDef.h"
// #include "PrimitivesFLOBOSS.h"
 #include "classUARTbuf.h"




/****************************************************************************************************/
/*                              L O W L E V E L     D E F I N E                                     */
/*                               ( d o n ' t     c h a n g e )                                      */
/****************************************************************************************************/
 #define strSize      49

 #define TimeOutCmmn  1500//
 #define TimeOutArch  3500//




/****************************************************************************************************/
/****************************************************************************************************/


/****************************************************************************************************/
/*                          E K 2 7 0   A D D R E S S   C O N S T S                                 */
/*                               ( d o n ' t     c h a n g e )                                      */
/****************************************************************************************************/
 #define HOSTunitDefault   1  //
 #define HOSTgroupDefault  1  //
 #define AccessLevel       5  //

 #define Qr_Point       ( ( 5 << 16 ) + ( 21 << 8 ) + ( 13 << 0 ) ) //5.21.13
 #define Hour_Point     ( ( 15<< 16 ) + ( 0 << 8 ) + ( 10 << 0 ) ) //15.0.10
 #define Pbar_Point     ( ( 46 << 16 ) + ( 0 << 8 ) + ( 15 << 0 ) )//46.0.15
 #define Ro_Point       ( ( 46 << 16 ) + ( 0 << 8 ) + ( 16 << 0 ) )//46.0.16
 #define N2_Point       ( ( 46 << 16 ) + ( 0 << 8 ) + ( 23 << 0 ) )//46.0.23
 #define CO2_Point      ( ( 46 << 16 ) + ( 0 << 8 ) + ( 24 << 0 ) )//46.0.24
 #define P_Point        ( ( 46 << 16 ) + ( 0 << 8 ) + ( 52 << 0 ) )//46.0.52
 #define T_Point        ( ( 46 << 16 ) + ( 0 << 8 ) + ( 53 << 0 ) )//46.0.53



 #define Qs_Point       ( ( 47 << 16 ) + ( 0 << 8 ) + ( 2 << 0 ) ) //47.0.2

 #define P_PointH       ( 3 - 1 )
 #define T_PointH       ( 4 - 1 )
 #define K_PointH       ( 5 - 1 )
 #define Vr_PointH      ( 6 - 1 )
 #define Vc_PointH      ( 7 - 1 )



 #define pzIdle          1  //
 #define pzCRC           2  //
 #define pzOK            3  //
 #define pzNoAnsw        4  //
//
 #define TimeOutMS       500  //
//
 #define erIOR           1  //Invalid Opcode request
 #define erIPN           2  //Invalid Parameter Number
 #define erILPN          3  //Invalid Logical Number / Point Number
 #define erIPT           4  //Invalid Point Type
 #define erRMD           5  //Received too many data bytes
 #define erRFD           6  //Received too few data bytes
 #define erNR1           7  //Did not receive 1 data byte
 #define erNR2           8  //Did not receive 2 data byte
 #define erNR3           9  //Did not receive 3 data byte
 #define erNR4           10 //Did not receive 4 data byte
 #define erNR5           11 //Did not receive 5 data byte
 #define erNR16          12 //Did not receive 16 data byte
 #define erOAR           13 //Outside valid address range
 #define erIHR           14 //Invalid history request
 #define erIFSTR         15 //Invalid FST request
 #define erIEE           16 //Invalid event entry
 #define erRMA           17 //Requested too many alarms
 #define erRME           18 //Requested too many events
 #define erWRO           19 //Write to read only parameter
 #define erSE            20 //Security error
 #define erISL           21 //Invalid security logon
 #define erISFP          22 //Invalid store and forward path
 #define erFPE           23 //Flash programming error
 #define erHCP           24 //History configuration in progress
 #define erSLH           63 //Requested security level too high
 #define erNAN           256//Floboss don't answer
 #define erNAR           257//there is No Archive Record



//
 #define CO2_adr         11314  //
 #define H2_adr          12314  //
 #define Rhoc_adr        13314  //
 #define N2_adr          14314  //
 #define dv_adr          15314  //
//
 #define Time_adr         1400  //


 #define Idle         0//
 #define Exit         1//
 #define ErrExit      2//


/****************************************************************************************************/
/****************************************************************************************************/






class FLOBOSS
{
  char ROCunit, ROCgroup, HOSTunit, HOSTgroup, OpID[3], ContractHour;
  usht Password, IndxHi, IndxLo, Error;
  
  uint InStrt, NofByte;
  UARTbuf *pUx;
  ArchData D;
  
  
private:  
//
  void setID(void);
  bool askFLOBOSS(void);

  void AskOpcode6(void);
  void AskOpcode7(DataTime *pDT);
  void AskOpcode17(void);
  void AskOpcode120(usht *pIndx);
  bool AskOpcode130(char HPointNum, char NofVals, usht StrtPointer);
  void AskOpcode180(uint Point, void *pVar, char Nbytes);
  void AskOpcode181(uint Point, void *pVar, char Nbytes);
  
  uint formAddress(void);
  void formPointAdr(uint PointAdr);
  
  void FormOpcode6(void);
  void FormOpcode7(void);
  void FormOpcode17(void);
  void FormOpcode120(void);
  void FormOpcode128(char HPointNum, char month, char day);
  void FormOpcode130(char HPointNum, char NofVals, usht StrtPointer);
  void FormOpcode165rd(char DataBaseNumb);
  void FormOpcode180(uint PointAdr);
  void FormOpcode181(uint PointAdr, char *pVal, char NofByte);

  char ReadArchive(DataTime *pData, FBarch *pArD, char NofRecs);
  usht RecordScan(usht IndxB, uint DataBgn, uint DataEnd);
  usht DataCheck(uint DataBgn, uint DataEnd, char NofVals);
  uint CalcEndOfDay(uint Data, uint Hour);
  uint CheckReWrite(uint I, uint Ibefor, uint Iafter);
  void FillNoData(uint NofRec, FBarch *pArD);
  char ReadArchData(uint Indx, uint NofRec, uint DataEnd, FBarch *pArD);
  void ReadArchVals(uint IndxBgn, char NofRec, char PointH, char *pVal, uint shift);
  

  void wrChar(char symbol) {(*pUx).WrBufOut(symbol); /*CheckSum += symbol;*/};
  float BUFtoFLOAT(void);
  usht BUFtoMIN(void);
  float BUFtoTEMP(void);
  float BUFtoPRES(void);
  usht BUFtoERR(void);

  void GetValue(uint InInd, char *pVar, char Nbytes);
  void RstValue(char *pVar, char Nbytes);
  void GetTime(uint InInd, DataTime *pDT);
  void RstTime(DataTime *pDT);
  
  
  void wrString(char *pSTR);
  void wrUShort(usht num);
  void wrDataTime(DataTime *pDT);
  void wrDTval(char DTval);
  void ParamSet(char col);
  void StrToDataTime(DataTime *pDT);
  char StrToChar(uint StrShft);
  bool CheckAnswer(void);
  void CheckError(void);
  bool TestAdr(uint InInd);
//  
public:
//
  FLOBOSS(UARTbuf *pUART, char ROC_unit, char ROC_group);
  
  
  bool GetCurrentParameters(GFGdata *pCurrData);
  bool GetGasPassport(GASpassport *pPass);
  char GetArMP(DataTime *pData, FBarch *pArD, char NofRecs);
  char GetArDay(DataTime *pData, FBarch *pArD);
  
  bool PutCO2(float CO2percent);
  bool PutN2(float N2percent);
  bool PutRhoc(float RhocVal);
  bool PutPbar(float PbarVal);
  
  bool startEK(void);
  bool getPARAMfl(uint Adr, float *pParam);
  bool getPARAMdt(uint Adr, DataTime *pDT);
  bool getPARAMui(uint Adr, uint *pParam);
  bool putPARAMui(uint Adr, uint Param);
  bool putPARAMuiHex(uint Adr, uint Param);
  bool putPARAMfl(uint Adr, float Param);
  
  bool getArch(DataTime *pBgn, char NofStr, char NofArh);
  
//
};
/****************************************************************************************************/
/****************************************************************************************************/



#endif